<?php
include_once(dirname(__FILE__)."/classes/Zreview.php");
/**
 * Tab này hiện thị thông tin từ csdl là bảng pl_gp_review
 * 
 * @author nhat
 *
 */
class ZadminGReview extends AdminTab
{
	/**
	 * Hàm dựng 
	 * khai báo thông tin về bảng dữ liệu 
	 * các thao tác 
	 * các trường hiển thị
	 */
	public function __construct()
	{
		global $cookie;
		$this->table = 'zgallery_review';
	 	$this->className = 'Zreview';
	 	$this->delete = true;
	 	$this->edit = true;
	 	/*Mảng action*/
		$genders = array(0 => $this->l('Not Approved'), 1 => $this->l('Approved'), 2 => $this->l('Pending'));
		$this->_select="d.*";
		$this->fieldsDisplay = array(
			'title' => array('title' => $this->l('Name Photo'), 'align' => 'center', 'width' => 53),
			'nickname' => array('title' => $this->l('Nick Name'), 'align' => 'center', 'width' => 55),
			'date_add' => array('title' => $this->l('Create Date'), 'type'=>'datetime' ,'align' => 'right', 'width' => 23),
			'active' => array('title' => $this->l('Status'), 'width' => 50, 'align' => 'center', 'callback'=>'printNewsIconStatus', 'orderby' => false, 'type' => 'select', 'select' => $genders, 'filter_key' => 'a!active'),
		);
		$this->_join = '
			LEFT JOIN '._DB_PREFIX_.'zgallery_photo_lang d ON (d.id_zgallery_photo=a.id_zgallery_photo AND d.id_lang='.$cookie->id_lang.')
		';
		parent::__construct();
	}
	
	/**
	 * Xử lý thông tin dc up lên
	 * @param unknown_type $token
	 */
	public function postProcess($token = NULL)
	{
		
		
		global $currentIndex,$cookie;
		$_GET['tabs']=1;
		if (Tools::isSubmit('changeStatus') && Tools::getValue('id_zgallery_review')){
			
			$id_zgallery_review=(int)Tools::getValue('id_zgallery_review');
			$Zreview=new Zreview($id_zgallery_review);
			$update = Db::getInstance()->Execute(
				'UPDATE `'._DB_PREFIX_.'zgallery_review` 
				SET active = '.(($Zreview->active==1)?0:1).' 
				WHERE `id_zgallery_review` = '.(int)($Zreview->id));
			
			if (!$update)
				$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
			Tools::redirectAdmin($currentIndex.'&tabs=1&conf=5&token='.$this->token);
		}
		parent::postProcess ();
	}
	/**
	 * Load js và css 
	 */
	public function loadJsCss (){
	echo ' 		
 		<script src="'._MODULE_DIR_.'plgallerypro/js/showPhoto/jquery.rating.pack.js" type="text/javascript" language="javascript"></script>
 		<link href="'._MODULE_DIR_.'plgallerypro/css/showPhotoBasic/photo.css" type="text/css" rel="stylesheet"/>
 		<script type="text/javascript">
			$(function(){ $("input[@type=radio].star").rating(); });
		</script>
 		';
	
	}
	
	/**
	 * Display update 
	 */
	 
	public function displayForm ($isMainTab = true){
		global $currentIndex,$cookie;	// dia chi index hien tai
		parent::displayForm();
		$id_zgallery_review=Tools::getValue ('id_zgallery_review');		
		if (!($Zreview = $this->loadObject(true)))
			return;
		
		$langtags = 'content';
		$this->loadJsCss ();
		echo '<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
			'.($Zreview->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$Zreview->id.'" /> ' : '');
		echo '
		<fieldset style="width:900px;">
				<legend>'.$this->l('Detailed Comment').'</legend>
				';
		echo '<br class="clear" /><label>'.$this->l('Nick Name').'</label>
				<div class="margin-form">
					<input style="width: 235px;" id="nickname" name="nickname" value="'.htmlentities(stripslashes($this->getFieldValue($Zreview, 'nickname')), ENT_COMPAT, 'UTF-8').'"/>
					<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
				</div>';
			echo '<div>';
		echo '
				<br class="clear" /><label>'.$this->l('Email').'</label>
				<div class="margin-form" >';
			echo '
					<input style="width: 235px;" id="email" name="email" value="'.htmlentities(stripslashes($this->getFieldValue($Zreview, 'email')), ENT_COMPAT, 'UTF-8').'"/>
				</div>';
			echo '<div>';
		echo '<br class="clear" /><label>'.$this->l('Content').'</label>
				<div class="margin-form">';
		foreach ($this->_languages as $language)
			echo '
				<div id="content_'.$language['id_lang'].'" style="float: left;'.($language['id_lang'] != $this->_defaultFormLanguage ? 'display:none;' : '').'">
					<textarea class="rte" cols="48" rows="5" id="content_'.$language['id_lang'].'" name="content_'.$language['id_lang'].'">'.htmlentities(stripslashes($this->getFieldValue($Zreview, 'content', $language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
					<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
				</div>';
		$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'content');
		echo '</div></div>';
		echo '
			<br class="clear" />
			<br class="clear" />
			<label>'.$this->l('Active:').' </label>
				<div class="margin-form">
					<input type="radio" name="active" id="active_on" value="1" '.($this->getFieldValue($Zreview, 'active') ==1? 'checked="checked" ' : '').'/>
					<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
					<input type="radio" name="active" id="active_off" value="0" '.($this->getFieldValue($Zreview, 'active') ==0? 'checked="checked" ' : '').'/>
					<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>';
					if ($this->getFieldValue($Zreview, 'active')==2)
						echo '<input type="radio" name="active" id="active_ff" value="2" checked="checked"/>
							<label class="t" for="active_ff"> <img src="../img/admin/forbbiden.gif" alt="Pending" title="Pending" /></label>';
		echo '
				</div>
			<div class="margin-form">
					<input type="submit" value="'.$this->l('   Save   ').'" name="submitAdd'.$this->table.'" class="button" /></div>
				<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
			</fieldset>
		</form> ';
	}
}
